package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021-7-9.<br><br>
 *
 * 阶乘后的零
 */
public class Topic172 {
    public static void main(String[] args) {
        Topic172 instance = new Topic172();

        System.out.println(instance.trailingZeroes(0));
        System.out.println(instance.trailingZeroes(3));
        System.out.println(instance.trailingZeroes(5));
        System.out.println(instance.trailingZeroes(10));
        System.out.println(instance.trailingZeroes(125));
    }

    public int trailingZeroes(int n) {
        int counter = 0;

        while (n >= 5) {
            counter += n / 5;
            n = n / 5;
        }

        return counter;
    }

    public int trailingZeroes2(int n) {
        if(n < 5) {
            return 0;
        }

        return n / 5 + trailingZeroes(n / 5);
    }
} 
